<template>
    <a-modal
        class="passwordSet"
        title="密码设置"
        :visible="passwordBox"
        @cancel="$emit('cancel')"
        okText="确认"
        cancelText="取消"
        @ok="submitPassword"
        >
        <eform
            :formData="formData"
            ref="password"
        ></eform>
    </a-modal>
</template>
<script>
import eform from "@/components/common/form"
export default {
    name:'editPassword',
    components:{eform},
    props:{
        passwordBox:Boolean,
        api:Function,
        apiFormData:Object
    },
    data(){
        let validatePassword=(rule,value,callback)=>{
            let reg=/^[0-9a-zA-Z]{6,12}$/
            if(value==''||reg.test(value)){
                callback()
                this.newPassword=value
                this.$refs.password.form.resetFields('confirmPassword')
            }else{
                callback(new Error('密码必须是6-12位数字和字母的组合'))
            }
        }
        let validateConfirmPassword=(rule,value,callback)=>{
            if(value==''||this.newPassword===value){
                callback()
            }else{
                callback(new Error('两次密码输入不一致'))
            }
        }
        const formData=[{
            label:'当前密码',
            prop:'pwd',
            type:'password',
            placeholder:'请输入当前密码',
            rules:[{required:true,message:'请输入当前密码'}]
        },{
            label:'新密码',
            prop:'newPwd',
            type:'password',
            placeholder:'请输入新密码',
            rules:[{required:true,message:'请输入新密码'},{validator:validatePassword}]
        },{
            label:'确认密码',
            prop:'confirmpass',
            type:'password',
            placeholder:'请输入确认密码',
            rules:[{required:true,message:'请输入确认密码'},{validator:validateConfirmPassword}]
        }]

        return{
            formData,
            newPassword:'',
        }
    },
    methods:{
        submitPassword(){
            this.$refs.password.form.validateFields().then(res=>{
                this.$emit('submitPassword',res)
                // this.getToken(editAdminPassword,{...res,'admin_id':this.adminId},(res=>{
                //     this.$message.success('修改成功')
                //     this.passwordBox=false
                // }))
            })
        }
    }
}
</script>